/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package epaper;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 *
 * @author Puneet
 */
public class DNAMain extends CommonClient implements Callable {

    

    
    public DNAMain(int city, String fileName, Date date) {
        super(null,city,fileName,date);
    }


    public void buildURL(String lang, int city, Date date) {

        int dateminusone = 0;
        Format format = new SimpleDateFormat("ddMMyyyy");
        String dateStr = format.format(date);
        String pageStr = new SimpleDateFormat("dd_MM_yyyy_").format(date);

        urlStr = new StringBuilder("http://epaper.dnaindia.com/");

        if(city == Cities.getInstance().AHMEDABAD){
            urlStr.append("dnaahmedabad/");
        } else if(city == Cities.getInstance().JAIPUR){
            urlStr.append("dnaahmedabad/");
        } else if(city == Cities.getInstance().BANGALORE){
            urlStr.append("dnabangalore/");
        }


        urlStr.append("epaperpdf/").append(dateStr.toString()).append("/");
        mergePaper = new StringBuilder(basefile + "DNA");
        dateminusone = date.getDate() - 1;
        if (dateminusone == 0) {
            switch (date.getMonth()) {
                //31 days in prev month
                case 0:
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                    dateminusone = 31;
                    break;
                case 4:
                case 6:
                case 9:
                case 11:
                    dateminusone = 30;
                    break;
                case 2:
                    dateminusone = 28;


            }
        }

        urlStr.append(dateminusone);




        switch (date.getDay()) {
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
                if(city == Cities.getInstance().PUNE || city == Cities.getInstance().AHMEDABAD || city == Cities.getInstance().JAIPUR || city == Cities.getInstance().BANGALORE){
                    String tempcity = Cities.getInstance().getCity(city);
                    urlStr.append(tempcity.toLowerCase()).append("%20main%20edition-pg");
                    mergePaper.append("_").append(tempcity);
                //} else if(city == Cities.getInstance().BANGALORE){
                    //urlStr.append(Cities.getInstance().getCity(city).toLowerCase()).append("-pg").append("%20main%20edition-pg");
                    //mergePaper.append("_").append(Cities.getInstance().getCity(city));
                } else {
                    urlStr.append("main%20edition-pg");
                }

                break;
            case 0:
                if(city == Cities.getInstance().PUNE){
                    urlStr.append("p").append("sunday-pg");
                    mergePaper.append("_").append(Cities.getInstance().getCity(city));
                } else if(city == Cities.getInstance().AHMEDABAD){
                    urlStr.append("sunday%20").append(Cities.getInstance().getCity(city).toLowerCase()).append("-pg");
                    mergePaper.append("_").append(Cities.getInstance().getCity(city));
                } else if(city == Cities.getInstance().JAIPUR){
                    urlStr.append(Cities.getInstance().getCity(city).toLowerCase()).append("%20main%20edition-pg");
                    mergePaper.append("_").append(Cities.getInstance().getCity(city));
                } else if(city == Cities.getInstance().BANGALORE){
                    urlStr.append("sunday%20").append(Cities.getInstance().getCity(city).toLowerCase()).append("-pg");
                    mergePaper.append("_").append(Cities.getInstance().getCity(city));
                } else {
                    urlStr.append("sunday-pg");
                }
                break;
            case 6:
                if(city == Cities.getInstance().PUNE || city == Cities.getInstance().AHMEDABAD || city == Cities.getInstance().JAIPUR || city == Cities.getInstance().BANGALORE){
                    String tempcity = Cities.getInstance().getCity(city);
                    urlStr.append(tempcity.toLowerCase()).append("%20main%20edition-pg");
                    mergePaper.append("_").append(tempcity);
                //} else if(city == Cities.getInstance().BANGALORE){
                //    urlStr.append("saturday%20").append(Cities.getInstance().getCity(city).toLowerCase()).append("-pg");
                 //   mergePaper.append("_").append(Cities.getInstance().getCity(city));
                } else {
                    urlStr.append("saturday-pg");
                }


        }
        System.out.println("urlStr : " + urlStr);

        mergePaper.append("_").append(pageStr).append(".pdf");
    }

    public String buildPageUrl(int pagenumber){
        return urlStr.toString() + pagenumber + "-0.pdf";
    }

}
